Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lint forbidding PEP-570 syntax #10660

Merged
merged 4 commits into from
Sep 4, 2023
Merged

Conversation

AlexWaygood
Copy link
Member

We don't want to start using PEP-570 syntax in typeshed yet, because we don't want to unnecessarily break compatibility with Python 3.7 (#10113) -- mypy users will not be able to check their code using --python-version 3.7 after we start using PEP-570 syntax in typeshed. However, now that we no longer run mypy or stubtest in CI using Python 3.7, none of our CI fails if somebody proposes using PEP-570 syntax in a PR (e.g. #10646 (comment) wouldn't have been caught if it hadn't been for @srittau's sharp eye!).

This PR proposes adding a simple lint to check_new_syntax.py so that we don't accidentally start using PEP-570 syntax in typeshed before we formally drop support for Python 3.7.

Comment on lines 30 to 34
def _visit_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
self.lineno = node.lineno
self.generic_visit(node)

visit_FunctionDef = visit_AsyncFunctionDef = _visit_function
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dance is necessary because ast.arguments instances don't have lineno attributes

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! My two thoughts were 1) stubs don't use lambdas 2) check_old_syntax.py

@hauntsaninja hauntsaninja merged commit af97a12 into python:main Sep 4, 2023
61 checks passed
@AlexWaygood AlexWaygood deleted the py37-lint branch September 4, 2023 22:41
@AlexWaygood
Copy link
Member Author

  1. check_old_syntax.py

ast_lints_that_dont_belong_in_flake8_pyi.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants